package dm.ui;

import java.util.Vector;

import javax.swing.JProgressBar;
import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;

public class JTableProgressModel extends AbstractTableModel
{
		
	private static final long serialVersionUID = 10548L;
	
	private Vector<MyTableRow> __rows = new Vector<MyTableRow>();
	
	//Day la header cua cac cot trong ban
	private String[] __columns = { "URL", "Total size (Kb)", "Num of File downloaded",  "Complete" };
	
	public JTableProgressModel()
	{
		
	}
	
	public String getColumnName(int column)
	{ 
	    return __columns[column];
	}
	
	public void addRow(String surl, long size, long files, JProgressBar pb)
	{		
		__rows.add(new MyTableRow(surl,size, files, pb));
		
		fireTableChanged(new TableModelEvent(this));		
	}
	
	public void addRow(MyTableRow pr)
	{		
		__rows.add(pr);
		
		fireTableChanged(new TableModelEvent(this));		
	}

	public int getColumnCount()
	{
		// TODO Auto-generated method stub
		return __columns.length;
	}

	public int getRowCount()
	{
		// TODO Auto-generated method stub
		return __rows.size();
	}	
	
	public Object getValueAt(int row, int column)
	{ 
		MyTableRow pr = __rows.get(row);
		switch(column)
		{
			case 0:	return pr.getUrlAddress();
			
			case 1: return pr.getTotalSize();
			
			case 2: return pr.getNumOfFile();
			
			case 3: return pr.getPbar();
			
			default: return null;
			
		}
	}
	
	public void removeRows(int row)
	{
		__rows.remove(row);
		fireTableChanged(new TableModelEvent(this));
	}

	public boolean isCellEditable(int row, int column)
	{
	
		return false;
	}

	public Class<?> getColumnClass(int column)
	{
		return getValueAt(0, column).getClass();
	}
}